/**
 * @author luzeyu & liangqiaowei
 */
package tiei.ajp.huffman.utils;

public class TreeNode<T> implements Comparable<TreeNode<T>> {
    int freq;
    T data;
    TreeNode<T> left = null;
    TreeNode<T> right = null;


    public TreeNode() {
        this.left = null;
        this.right = null;
        this.freq = -1;
    }

    public TreeNode(int freq, T data) {
        this.freq = freq;
        this.data = data;
        this.left = null;
        this.right = null;
    }

    public TreeNode(T data) {
        this.data = data;
        this.left = null;
        this.right = null;
        this.freq = -1;
    }

    // 用于非叶节点
    public TreeNode(int freq, TreeNode<T> left, TreeNode<T> right) {
        this.freq = freq;
        this.data = null; // 内部节点没有字符
        this.left = left;
        this.right = right;
    }

    public boolean isLeaf() {
        return this.data != null;
    }

    @Override
    public int compareTo(TreeNode<T> other) {
        return this.freq - other.freq;
    }
}